-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add commit ID to version output #370
Add commit ID to version output #370
Conversation
1c1d514
to
65d9898
Compare
@mgoerens thanks for this. The linter is grumpy ^ https://github.com/redhat-certification/chart-verifier/actions/runs/5508530811/jobs/10039939259?pr=370#step:7:154 |
65d9898
to
1cb9515
Compare
This should be fixed now. |
Fixes #370 |
Makefile
Outdated
.PHONY: build | ||
build: | ||
go build -ldflags "-X 'github.com/redhat-certification/chart-verifier/cmd.CommitIDLong=$(COMMIT_ID_LONG)'" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use the existing bin
target instead of having a separate build
target. Also add this to bin_win
for now.
I'll collapse those targets at some point in the future, but for now, we can duplicate the logic in both places.
cmd/version.go
Outdated
func init() { | ||
rootCmd.AddCommand(NewVersionCmd()) | ||
} | ||
|
||
// CommitIDLong contains the commit ID the binary was build on. It is populated at build time by ldflags. | ||
// If you're running from a local debugger it will show an empty commit ID. | ||
var CommitIDLong string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's preseed this with a value of unknown
cmd/version.go
Outdated
func NewVersionCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "print the chart-verifier version information", | ||
Long: "git commit information for this particular binary build is included at build time and can be accessed by this command", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave the long description out
cmd/version.go
Outdated
return err | ||
} | ||
fmt.Fprint(out, string(marshalledVersion)) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this else
here. Instead, return nil
in the if
block after line 56.
E.g. (disregard pseudocode names, just demonstrating structure)
func runVersion(...) ... {
if asData {
printAsDataHopefullySuccessfully()
return nil
}
printThingsNormally()
return nil
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I was thinking about this and was balanced. Good that you have a strong opinion on this, that helps making a decision :)
@mgoerens Left a couple of comments. The CI complaint is an interesting way. Effectively what it's implying is that the chart-verifier version output is used in report generation, and since we've changed its output, we're breaking our fixtures. Normally, I'd say we can update our fixtures, however I think for this case, I think we want to make sure we're backwards compatible with the reports because changing that has some hefty implications. Please let me know if you need any guidance with this. I'd also recommend you are rebased off of main at any given time before submitting your PR, just to rule out any differences between your branch and main when it comes to CI. It can be a little finicky with differences between a PR and main. |
Quick note, the problem is two-fold.
With this in mind, you can take this one of two ways, I think: a) The easiest thing to do is just to add the commit information as a flag value. In other words, leave b) Update the e2e tests[1] to comply with expectations. Maybe it can use the I'm perfectly fine with both options. Your choice! |
The code does still make use of pkg/chartverifier/version.GetVersion include apiversion "github.com/redhat-certification/chart-verifier/pkg/chartverifier/version"
[...]
var Version = VersionContext{
Version: apiversion.GetVersion(),
Commit: CommitIDLong,
} I ran I'll look at option a) and b) in details tomorrow. |
1cb9515
to
7bd9203
Compare
Aha, missed this. Thanks for pointing it out! |
4dcd90a
to
4d8a725
Compare
All right. Pipeline passes. Though I still don't manage to reproduce it locally, the error seemed to be coming from the lack of newline in the output of So I added a newline and now all tests pass. Full list of changes (from commit message):
Reg. the last point: the "build-and-test" script is, as the name suggests, comprised of two parts: first it builds the container image, then it tests the image using There are multiple issues with the "test" part which makes this script not usable as-is (prior to this PR):
But before putting further effort into fixing the "test" part of this script, it appears to me like we don't need this script to be able to test a docker image anymore. The pipeline takes care of that in a next step (actually running some extensive tests). AFAICT this script is never called without the My suggestion is to not fix this part and to consider dropping the "test" part of the |
Opened #378 for the buildandtest issue |
- use ldflags to injects the git commit ID at build time - add the commit ID to the version output - add the possibility to get the version and commit information in a JSON format - adapt the tests to make use of the JSON output - adapt Dockerfile to make use of the make bin target - fix path to chart used to test the built docker image in buildandtest script (moved as part of !271) and make use of the JSON output close redhat-certification#362 Signed-off-by: mgoerens <[email protected]>
4d8a725
to
e73878a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Thanks @mgoerens!
Example output: